Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Wx_RecoderMgr = undefined;
var o = window.wx;
var exp_Wx_RecoderMgr = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
    this.recorder = null;
    this.videoPath = null;
    this.getvideo = false;
    this.viodeTime = 0;
    this.start_time = 0;
    this.end_time = 0;
    this.recordering = false;
    this.recorder_state = "stop";
    this.recorder_share_btton = null;
  }
  return babel_createClass(_ctor, [{
    key: "start",
    value: function start() {
      var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 7200;
      if (0 != this.recorder.isFrameSupported() && o) {
        if ("stop" != this.recorder_state) {
          this.stop(), this.recorder.abort();
        }
        this.recordering = true;
        this.viodeTime = 0;
        this.start_time = new Date().getTime();
        console.log("start_time:", this.start_time);
        this.recorder.start({
          fps: 24,
          bitrate: 1e3,
          duration: 7200,
          hookBgm: true
        });
        console.log("start record");
        this.recorder_state = "start";
      }
    }
  }, {
    key: "initGameRecorderManager",
    value: function initGameRecorderManager() {
      var _this159 = this;
      if (o) {
        this.recorder = o.getGameRecorder();
        this.recorder.on("stop", function (e) {
          _this159.onStop(e);
        });
      }
    }
  }, {
    key: "onStop",
    value: function onStop(e) {
      this.recordering = false;
      this.videoPath = "";
      this.getvideo = false;
      console.log("onStop", this.viodeTime);
    }
  }, {
    key: "shareAppMessage",
    value: function shareAppMessage(e, t) {
      if (!o) {
        return void (e && e(true));
      }
      if (1 == this.recordering) {
        return;
      }
      console.log("开始分享", t);
      t && "" != t.videoPath && null != t.videoPath && null != t.videoPath && (this.videoPath = t.videoPath);
      if ("" == this.videoPath) {
        return void (this.getvideo = true);
      }
      var n = {
        videoPath: this.videoPath,
        videoTopics: ["豆豆探险闯关", "彩蛋", "小游戏"],
        withVideoId: true,
        videoTag: t && t.videoTag ? t.videoTag : "",
        defaultBgm: t.defaultBgm ? t.defaultBgm : ""
      };
      console.log("extra", n);
      o.shareAppMessage({
        channel: "video",
        templateId: "2hnxv56llbf2832gep",
        query: "_nickname=" + t.mapauthor + "&mapid=" + t.mapid + "&mapUrl=" + t.mapUrl,
        extra: n,
        success(t) {
          console.log("分享视频成功", t);
          e && e(true);
        },
        fail(t) {
          console.log("分享视频失败", t);
          e && e(false);
        }
      });
    }
  }, {
    key: "request",
    value: function request(e, t) {
      o.request({
        url: "hwxps://gate.snssdk.com/developer/api/get_video_info",
        method: "POST",
        data: {
          alias_ids: e
        },
        success(e) {
          t && t(e);
        },
        fail(e) {
          t && t(e);
        }
      });
    }
  }, {
    key: "shareVideo",
    value: function shareVideo(e) {
      if (o) {
        1 != this.recordering && ("" != this.videoPath || (this.getvideo = true));
      } else {
        e && e(true);
      }
    }
  }, {
    key: "stop",
    value: function stop() {
      if (o) {
        console.log("结束录制");
        this.recorder.stop();
        this.end_time = new Date().getTime();
        console.log("end_time:", this.end_time);
        this.recorder_state = "stop";
      }
    }
  }, {
    key: "pause",
    value: function pause() {
      if ("pause" != this.recorder_state && o) {
        this.recorder.pause();
        this.recorder_state = "pause";
      }
    }
  }, {
    key: "resume",
    value: function resume() {
      o && this.recorder.resume();
    }
  }, {
    key: "createRecorderShareButton",
    value: function createRecorderShareButton(e, t) {
      var n;
      var o = this.end_time - this.start_time;
      n = o >= 6e4 ? [[0, 6e4]] : [[0, o]];
      console.log("录屏时长:", n);
      if (null == this.recorder_share_btton) {
        this.recorder_share_btton = window.wx.createGameRecorderShareButton({
          style: {
            left: e.left,
            top: e.top,
            height: e.height,
            color: "#ffffff",
            textAlign: "center",
            fontSize: 16,
            borderRadius: 4,
            iconMarginRight: e.width,
            paddingLeft: 10,
            paddingRight: 10,
            backgroundColor: "transparent"
          },
          icon: "",
          text: "",
          share: {
            query: "a=1&b=2",
            bgm: "",
            atempo: 1,
            timeRange: n
          }
        });
        console.log("createRecorderShareButton.onTap", this.recorder_share_btton.onTap);
        this.recorder_share_btton.onTap(function (e) {
          console.log("错误码：".concat(e.error.code, "，错误信息：").concat(e.error.message));
        });
      }
      this.recorder_share_btton.show();
    }
  }, {
    key: "Hide_Recorder_btn",
    value: function Hide_Recorder_btn() {
      this.recorder_share_btton && this.recorder_share_btton.hide();
    }
  }], [{
    key: "getInstance",
    value: function getInstance() {
      if (null == this._instance) {
        this._instance = new _ctor();
        this._instance.initGameRecorderManager();
      }
      return this._instance;
    }
  }]);
}();
exports.Wx_RecoderMgr = exp_Wx_RecoderMgr;
exp_Wx_RecoderMgr._instance = null;